<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/31 0031
 * Time: 上午 11:12
 */

namespace Home\Controller;


use Think\Controller;

class RegController extends Controller

{

    public function index(){

        if(IS_POST){
            $data=i('post.');
            $data['password']=md5(i('post.')['password']);

            $username=m('membersuser')->find();

            if ($data['username']==$username['username']){
                $this->success('用户名也存在');exit;
            }

            $res=$this->check_verify($_POST['code']);
            if(!$res){
                $this->error("验证码错误");exit;
            }

            session('username',$data['username']);
             m('membersuser')->add($data);
            $this->success('注册成功',u('home/login/index'));exit;


        }

        $this->display();
    }


    public function code(){

        $Verify =     new \Think\Verify();
        $Verify->fontSize = 30;
        $Verify->length   = 3;
        $Verify->useNoise = true;
        $Verify->entry();
    }

    public function check_verify($code, $id = ''){
        $verify = new \Think\Verify();
        return $verify->check($code, $id);
    }
}